package com.itqf.springboot_mvc.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * projectName: springboot_part
 *
 * @author: 赵伟风
 * time: 2021/9/17 17:22
 * description:性别的序列化类
 */
public class SexSerializer extends JsonSerializer<Integer> {
    /**
     *
     * @param integer 本次的结果  0 、1
     * @param jsonGenerator 给你写出结果的对象
     * @param serializerProvider
     * @throws IOException
     */
    @Override
    public void serialize(Integer integer, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        //进行格式化
        String sex = "女";
        if (integer == 0) {
             sex = "男";
        }

        jsonGenerator.writeString(sex);
    }
}
